<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>WELCOME TO FILE MANAGER!!!</title>
</head>
<body>
<%@ page import="file_functions.*, java.util.Vector, java.io.*" %>
<%!Manager man = new Manager(null);%>
<%!int sort_name = 1;%>
<%!int sort_size = 0;%>
<%!int sort_date = 0;%>

<br>
<%
if (request.getParameter("s_name") != null)
{
	int par = Integer.parseInt(request.getParameter("s_name"));
	if (par != sort_name)
	{
		sort_name = par;
		sort_size = 0;
		sort_date = 0;
	}
}

if (request.getParameter("s_size") != null)
{
	int par = Integer.parseInt(request.getParameter("s_size"));
	if (par != sort_size)
	{
		sort_name = 0;
		sort_size = par;
		sort_date = 0;
	}
}

if (request.getParameter("s_date") != null)
{
	int par = Integer.parseInt(request.getParameter("s_date"));
	if (par != sort_date)
	{
		sort_name = 0;
		sort_size = 0;
		sort_date = par;
	}
}

if (request.getParameter("file") != null)
	man.cd_command(new String(request.getParameter("file").getBytes("ISO-8859-1"), "UTF8"));

Vector<Files_info> result = man.ls_command(true, true, sort_name, sort_size, sort_date);
%>
<%= man.get_name() %>
<br>
<form ACTION="int_upload.jsp?dir=<%= man.get_name()%>" METHOD=POST>
<INPUT TYPE = "submit" VALUE = "Upload file" NAME = "button2">
</form>
<%
session.setAttribute("fold", man.get_name().getBytes("UTF8")); %>
<form ACTION="new_folder.jsp" METHOD=POST>
<INPUT TYPE = "submit" VALUE = "Create folder" NAME = "button3">
</form>

<form ACTION="rename1.jsp?dir=<%= man.get_name()%>" METHOD=POST>
<INPUT TYPE = "submit" VALUE = "Rename" NAME = "button4">
</form>
<%
session.setAttribute("dir", man.get_name().getBytes("UTF8")); %>
<form ACTION="del_or_dis.jsp" METHOD=POST>
<INPUT TYPE = "submit" VALUE = "Delete selected" NAME = "button">
<br>
<br>
<INPUT TYPE = "submit" VALUE = "Displace selected" NAME = "button">

<TABLE cellspacing = "15">
<TR>
<TH><a href = "?s_name=<%= man.sort_val(sort_name)%>">Name<%= man.sort_sign(sort_name)%></a></TH>
<TH><a href = "?s_size=<%= man.sort_val(sort_size)%>">Size<%= man.sort_sign(sort_size)%></a></TH>
<TH><a href = "?s_date=<%= man.sort_val(sort_date)%>">Last modify date<%= man.sort_sign(sort_date)%></a></TH>
<TH></TH>
</TR>
<% for (int i = 0; i < result.size(); i++)
{ 
%>
<TR>
<% if (!result.get(i).isFile)
{
%>
 <TD> <a href = "?file=<%= result.get(i).name %>"><%= result.get(i).name %></a></TD>
 <%}
else
{%>
<TD> <a href = "Download?file=<%= result.get(i).fullName %>"><%= result.get(i).name%></a></TD>
<%} %>
 <TD> <%= result.get(i).size %></TD>
 <TD> <%= result.get(i).date %></TD>
 <% if (!result.get(i).name.equals("..")) {  %>
 <TD><input NAME = "check" VALUE = "<%= result.get(i).name%>" TYPE = "checkbox"></TD>
 <%} %>
</TR>
<% } %>
</TABLE>
</form>

</body>
</html>